package com.alm.token.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.persenter.MyPreenter;

/**
 * Created by Devin.Fu on 7/29/15.
 * 容纳一个fragment，类似于FragmentDialog
 */
public class FragmentHolderActivity extends BaseActivity {

    public final static String KEY_FRAGMENT_TYPE = "fragment_type";
    public final static String KEY_FRAGMENT_DATA = "fragment_data";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (savedInstanceState == null) {

            Intent tIntent = getIntent();
            Class<?> tFragmentClass = (Class<?>) tIntent.getSerializableExtra(KEY_FRAGMENT_TYPE);
            Bundle tData = tIntent.getBundleExtra(KEY_FRAGMENT_DATA);

            Fragment tFragment = null;
            try {
                tFragment = (Fragment) tFragmentClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (tFragment != null && tData != null)
                tFragment.setArguments(tData);

            if (tFragment != null) {
                getSupportFragmentManager().beginTransaction().add(R.id.fragmentHolderActivity_container_fl, tFragment).commitAllowingStateLoss();
            }
        }

    }

    @Override
    protected MyPreenter initPreenter() {
        return null;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fragment_holder;
    }

    @Override
    protected void initVariables() {

    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragmentHolderActivity_container_fl);
        if (f != null) {
            f.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public void onClick(View view) {

    }
}
